﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProjectManagement
{
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
    [System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
    public class CollectionProjects
    {
        private List<Project> _colProjects;

        public CollectionProjects()
        {
            _colProjects = new List<Project>();
        }

        [System.Xml.Serialization.XmlElementAttribute("Projects", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public List<Project> ColProjects
        {
          get { return _colProjects; }
          set { _colProjects = value; }
        }


        public void ValidateProject(Project project)
        {
            var lstErrors = new List<string>();
            foreach (Project p in _colProjects)
            {
                if(p.Name.Trim().ToUpper() == project.Name.Trim().ToUpper())
                {
                    lstErrors.Add("Ya existe un proyecto con este nombre.");
                }

                if (p.Path.Trim().ToUpper() == project.Path.Trim().ToUpper())
                {
                    lstErrors.Add("Ya existe un proyecto con esta ruta.");
                }

                if (p.ProjectGuid == project.ProjectGuid)
                {
                    lstErrors.Add("Ya existe un proyecto con este GUID. Contacte con el administrador.");
                }

                if (lstErrors.Count > 0)
                {
                    var sb = new StringBuilder();
                    foreach (string error in lstErrors)
                    {
                        sb.AppendLine(error);
                    }
                    throw new System.ComponentModel.DataAnnotations.ValidationException(sb.ToString());
                }
            }
        }
    }
}


